﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DynamicComparer;
using System.Data;
using Shuba.Model;
using Shuba.Business;
using System.Configuration;

namespace Shuba.Web.cdc
{
    public partial class cdc_replacement_operator : basePage
    {
        string msg = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitSort();
                //bindDdl();
                BindData();                
            }
        }

        //private void bindDdl()
        //{            
        //    ddlStatus.Items.Clear();
        //    ddlStatus.Items.Add(new ListItem("-Select-", ""));
        //    ddlStatus.Items.Add(new ListItem("All", "All"));

        //    Business.CDC _CDC = new Business.CDC();
        //    Model.CDCInfo _CDCInfo = new Model.CDCInfo();
        //    List<string> list = _CDC.ListReplacementOp();
        //    foreach (string info in list)
        //        ddlStatus.Items.Add(new ListItem(//(info.TRX_MAP_CODE + "-" + info.TRX_TYPE_NAME + "-" + info.CHANNEL + "-" + info.TRX_GROUP_NAME, info.TRX_MAP_CODE + "~" + info.GL_CODE + "~" + info.COST_CENTER + "~" + info.ACCT_TRF_NO + "~" + info.ACCT_OWNER_NAME + "~" + info.BANK_NAME + "~" + info.SETL_SRC + "~" + info.SETL_SRC_DESC + "~" + info.CHANNEL_CODE + "~"));
        //}

        void BindData()
        {
            Shuba.Business.CDC _CDC = new Shuba.Business.CDC();
            DataSet list = _CDC.GetListReplacementOp(txtSearch.Text);

            gvList.DataSource = list;            
            gvList.DataBind();            

            if (gvList.Rows.Count == 0)
            {
                ApprovalPnl2.Visible = false;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Shuba.Business.CDC cdc = new Shuba.Business.CDC();

            //cek ada nilai urgent atau ngga.
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                GridViewRow row = gvList.Rows[i];
                DropDownList ddlStatus = (DropDownList)row.FindControl("ddlStatus");

                if (ddlStatus.SelectedValue == "-1")
                {
                    
                }
                else
                {
                    string nip = ddlStatus.SelectedItem.Text;
                    string id = Convert.ToString(gvList.DataKeys[row.RowIndex].Values["PROSPECT_ID"].ToString());
                    cdc.SetReplacementOperator(nip, id);
                }
                
            }

            msg = "Completed!";
            AlertAndRedirect(msg, "cdc_replacement_operator.aspx");
            return;
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void gvList_Sorting(object sender, GridViewSortEventArgs e)
        {

        }

        protected void btnReplace_Click(object sender, EventArgs e)
        {
            Response.Redirect("cdc_replacement_operator.aspx");
        }
    }
}
